<template>
  <BasicModal v-bind="$attrs" @register="register" showFooter :title="getTitle" width="70%" :showOkBtn="false"
    :loading="loading">
    <div style="width: 100%">

      <Descriptions title="预收款信息">
        <DescriptionsItem label="预收款单号">{{ dataJson.zhuTid }}</DescriptionsItem>
        <DescriptionsItem label="客户编号">{{ dataJson.keHuBianHao }}</DescriptionsItem>
        <DescriptionsItem label="业务员名称">{{ dataJson.yeWuYuan }}</DescriptionsItem>
        <DescriptionsItem label="销售单号">{{ dataJson.xiaoShouDanHao }}</DescriptionsItem>
        <DescriptionsItem label="货币类型">{{ dataJson.huoBiLeiXing }}</DescriptionsItem>
        <DescriptionsItem label="预收款总金额">{{ dataJson.yuShouKuanZongJinE }}</DescriptionsItem>
        <DescriptionsItem label="实际预收款金额">{{ dataJson.shiJiYuShouKuanJinE }}</DescriptionsItem>
        <DescriptionsItem label="实际预收款人民币金额">{{ dataJson.shiJiYuShouKuanRenMinBiJinE }}</DescriptionsItem>
      </Descriptions>

    </div>
    <div style="width: 100%; height: 450px">
      <!-- v-on="gridEvents" overflow: hidden -->
      <vxe-grid ref="tableRef" v-bind="gridOptions">
        <template #toolbar_buttons>

        </template>

      </vxe-grid>


    </div>

  </BasicModal>
</template>
<script lang="ts" setup>
import { ref, computed, unref, h, toRaw, reactive } from 'vue';

import {
  BasicTableProps,
  VxeGridInstance
} from '@/components/VxeTable';

import { yuhsouColumns } from './role.data';
import { BasicModal, useModalInner } from '@/components/Modal';

import { BasicTree, TreeItem } from '@/components/Tree';
import { yuShouDetail, approveSubmit, shouKuanQueRenItemList } from '@/api/heng/ywManage';

import { Descriptions, DescriptionsItem } from 'ant-design-vue';

import { useMessage } from "@/hooks/web/useMessage";

const emit = defineEmits(['success', 'register']);
const isUpdate = ref(true);
const treeData = ref<TreeItem[]>([]);
const { createMessage } = useMessage();
const mouldMainId = ref("");

const applyViewShow = ref(false);
const visible = ref(false);
const msgList = ref([]);

const tableRef = ref<VxeGridInstance>();



const loading = ref(false);

const dataJson = ref({});


const gridOptions = reactive<BasicTableProps>({
  // keepSource: true,
  border: true,
  showOverflow: true,
  size: 'mini',
  height: 'auto', // 'auto'
  columns: yuhsouColumns,
  exportConfig: {},
  filterConfig: {
    remote: true,
  },
  toolbarConfig: {
    slots: {
      buttons: 'toolbar_buttons',
    },
    refresh: true,
  },

  pagerConfig: {
    enabled: false
  },

});


const [register, { setModalProps, closeModal }] = useModalInner(async (data) => {
  //打开弹层后的回调
  // resetFields();
  setModalProps({ confirmLoading: false });


  tableRef.value?.reloadData([]);
  let dJson = { yushouNo: data.record.orderNo };
  loading.value = true;
  yuShouDetail(dJson).then(res => {
    loading.value = false;
    tableRef.value?.reloadData(data.record.children);
    if (res && res.code == 200) {
      dataJson.value = res.data
    } else {
      createMessage.error(res.message);
    }
    dataJson.value = res.data;
  })

});

const getTitle = computed(() => ('预收款信息'));




function applyViewClose() {
  applyViewShow.value = false;
}

//async function handleSubmit()

const handleSubmit = () => {
  try {

    let data = unref(dataJson.value);

    console.log(data);
    loading.value = true;
    approveSubmit(data).then(res => {
      loading.value = false;
      sunccFn(res)
    })


  } catch (e) {
    console.log(e)
  } finally {
    setModalProps({ confirmLoading: false });

  }
}



function sunccFn(result) {
  if (result && result.code == 200) {
    applyViewClose();
    createMessage.success(result.message);
    closeModal()
    emit('success');
  } else {
    createMessage.error(result.message);
  }

}

function cancelFn() {
  //  tableRef.value.clearValidate();
}

function handleOk() {
  visible.value = false;
}

</script>
<style lang="less">
.item-row {
  margin: 0 auto;

  //padding-left: 5%;
  .ant-form-item-label {
    flex: 0 0 28.5%;
    max-width: 28.5%;
  }
}

.lqfp-8 {
  //padding-left: 9% !important;

}
</style>
